/*
 * // Bristleback plugin - Copyright (c) 2010 bristleback.googlecode.com
 * // ---------------------------------------------------------------------------
 * // This program is free software; you can redistribute it and/or modify it
 * // under the terms of the GNU Lesser General Public License as published by the
 * // Free Software Foundation; either version 3 of the License, or (at your
 * // option) any later version.
 * // This library is distributed in the hope that it will be useful,
 * // but without any warranty; without even the implied warranty of merchantability
 * // or fitness for a particular purpose.
 * // You should have received a copy of the GNU Lesser General Public License along
 * // with this program; if not, see <http://www.gnu.org/licenses/lgpl.html>.
 * // ---------------------------------------------------------------------------
 */

package pl.bristleback.server.bristle.binding;

import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;

import java.util.ArrayList;
import java.util.List;

/**
 * Wrapper class containing list of errors and object to which data was bound.
 * <p/>
 * Created on: 2011-02-27 16:59:47 <br/>
 *
 * @author Wojciech Niemiec
 */
public class BindingResult<T> {
  private static Logger log = Logger.getLogger(BindingResult.class.getName());

  private Object processedObject;
  private String currentPath;

  private List<BindingError> errors;
  private T result;

  public BindingResult(T bean) {
    this.result = bean;
    this.processedObject = bean;
    errors = new ArrayList<BindingError>();
    currentPath = StringUtils.EMPTY;
  }

  public boolean hasErrors() {
    return !errors.isEmpty();
  }

  public void addError(BindingError error) {
    errors.add(error);
  }

  public List<BindingError> getErrors() {
    return errors;
  }

  public T getResult() {
    return result;
  }

  public Object getProcessedObject() {
    return processedObject;
  }

  public void setProcessedObject(Object processedObject) {
    this.processedObject = processedObject;
  }

  public String getCurrentPath() {
    return currentPath;
  }

  public void setCurrentPath(String currentPath) {
    this.currentPath = currentPath;
  }
}
